package com.xiaobo.bodada.controller;

import com.xiaobo.bodada.annotation.AuthCheck;
import com.xiaobo.bodada.common.BaseResponse;
import com.xiaobo.bodada.common.ErrorCode;
import com.xiaobo.bodada.common.ResultUtils;
import com.xiaobo.bodada.constant.UserConstant;
import com.xiaobo.bodada.exception.ThrowUtils;
import com.xiaobo.bodada.mapper.UserAnswerMapper;
import com.xiaobo.bodada.model.vo.AppAnswerCountVO;
import com.xiaobo.bodada.model.vo.AppAnswerResultCountVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/*
* App 数据统计
* */
@Slf4j
@RestController
@RequestMapping("/app/statistic")
public class AppStatisticController {
    @Resource
    private UserAnswerMapper userAnswerMapper;

    /**
     * 统计应用回答次数
     */
    @GetMapping("/answer_count")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse<List<AppAnswerCountVO>> getAppAnswerCount(){
        List<AppAnswerCountVO> appAnswerCountVOList = userAnswerMapper.doAppAnswerCount();
        return ResultUtils.success(appAnswerCountVOList);
    }
    /*
    * 应用回答分布统计
    * */
    @GetMapping("/answer_result_count")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse<List<AppAnswerResultCountVO>> getAppAnswerResultCount(Long appId){
        ThrowUtils.throwIf(appId == null, ErrorCode.PARAMS_ERROR);
        List<AppAnswerResultCountVO> appAnswerResultCountVOS = userAnswerMapper.doAppAnswerResultCount(appId);
        return ResultUtils.success(appAnswerResultCountVOS);
    }
}
